package com.winhxd.b2c.customer.controller;

import com.winhxd.b2c.common.constant.BusinessCode;
import com.winhxd.b2c.common.domain.PagedList;
import com.winhxd.b2c.common.domain.ResponseResult;
import com.winhxd.b2c.common.domain.common.PagedCondition;
import com.winhxd.b2c.common.domain.customer.condition.DeliveryInfoCondition;
import com.winhxd.b2c.common.domain.customer.model.CustomerDeliveryInfo;
import com.winhxd.b2c.common.feign.customer.DeliveryInfoServiceClient;
import com.winhxd.b2c.customer.service.DeliveryInfoService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lishaoping
 * @Description:
 * @date 2019年1月7日20:33:20
 */
@Api(value = "api - Shopping", tags = "DeliveryInfo")
@RestController
public class DeliveryInfoServiceController implements DeliveryInfoServiceClient {

    @Autowired
    private DeliveryInfoService deliveryInfoService;

    private Logger logger = LoggerFactory.getLogger(DeliveryInfoServiceController.class);

    @Override
    public ResponseResult<Boolean> saveDeliveryInfo(@RequestBody DeliveryInfoCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<Boolean>();
        try {
            result.setData(deliveryInfoService.saveDeliveryInfo(condition));
        } catch (Exception e) {
            logger.error("saveDeliveryInfo保存配送方式失败：",e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    @Override
    public ResponseResult<Boolean> deleteDeliveryInfo(@RequestBody DeliveryInfoCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<Boolean>();
        try {
            result.setData(deliveryInfoService.deleteDeliveryInfo(condition));
        } catch (Exception e) {
            logger.error("saveDeliveryInfo删除配送方式失败：",e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    @Override
    public ResponseResult<Boolean> unusedDeliveryInfo(@RequestBody DeliveryInfoCondition condition) {
        ResponseResult<Boolean> result = new ResponseResult<Boolean>();
        try {
            result.setData(deliveryInfoService.unusedDeliveryInfo(condition));
        } catch (Exception e) {
            logger.error("unusedDeliveryInfo禁用或启用配送方式失败：",e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    @Override
    public ResponseResult<List<CustomerDeliveryInfo>> findDeliveryInfo() {
        ResponseResult<List<CustomerDeliveryInfo>> result = new ResponseResult<List<CustomerDeliveryInfo>>();
        try {
            result.setData(deliveryInfoService.findDeliveryInfo());
        } catch (Exception e) {
            logger.error("findDeliveryInfo查询（不分页）配送方式失败：",e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    @Override
    public ResponseResult<PagedList<CustomerDeliveryInfo>> findDeliveryInfoTOPage(@RequestBody PagedCondition condition) {
        ResponseResult<PagedList<CustomerDeliveryInfo>> result = new ResponseResult<PagedList<CustomerDeliveryInfo>>();
        try {
            result.setData(deliveryInfoService.findDeliveryInfoTOPage(condition));
        } catch (Exception e) {
            logger.error("findDeliveryInfoTOPage查询（分页）配送方式失败：",e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }

    @Override
    public ResponseResult<CustomerDeliveryInfo> findDeliveryInfoById(@PathVariable("id") Long id) {
        ResponseResult<CustomerDeliveryInfo> result = new ResponseResult<CustomerDeliveryInfo>();
        try {
            result.setData(deliveryInfoService.findDeliveryInfoById(id));
        } catch (Exception e) {
            logger.error("findDeliveryInfoById查询配送方式ById失败：",e);
            result.setCode(BusinessCode.CODE_1001);
        }
        return result;
    }
}
